package com.example.administrator.myapplication;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Administrator on 2016/12/7.
 */

public class Json {
    public  static  String Json(final String path, final JSONObject json){
        BufferedReader in =null;
        String result = "";
        OutputStream os = null;

        try {
            URL url = new URL(path);
            String content = String.valueOf(json);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5000);
            conn.setRequestMethod("GET");
            conn.setRequestProperty("aqpikey","ef5a271b9d4e3a0f64eb1cd14149bc1e");
            conn.setRequestProperty("ser-Agent","Fiddler");
            conn.setRequestProperty("Content-Type","application/json");
            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            if(conn.getResponseCode()==200){
                while((line = in.readLine())!=null){
                    result+=line;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return  "错误";
        }finally {
            try {
                if (os!=null){
                    os.close();
                }if (in!=null){
                    in.close();
                }
            }catch (IOException ex){
                ex.printStackTrace();
            }
        }
        return  result;
    }
}
